/*
 * mirrorslst.h
 *
 *  Created on: Jan 4, 2009
 *      Author: yospaly
 */

#ifndef MIRRORSLST_H_
#define MIRRORSLST_H_

#include <wx/filesys.h>
#include "common.h"

struct MirrorInfo {
	wxString name;
	wxString url;
	wxString continent;
	wxString country;
};

WX_DECLARE_OBJARRAY(MirrorInfo, MirrorInfoArray);
WX_DECLARE_STRING_HASH_MAP(MirrorInfoArray, MirrorsHash);

#define MIRRORS_LIST_URL _T("http://cygwin.com/mirrors.lst")

class MirrorsList {
public:
	static MirrorsList& get() {
		return self;
	}
	
	bool reload_mirrors();
	bool init();
	
	wxArrayString get_continents() {
		wxArrayString continents;

		ArrayStringHash::iterator it;
	    for( it = _continent_hash.begin(); it != _continent_hash.end(); ++it ) {
	    	continents.Add(it->first);
	    }
	    
	    return continents;
	}
	wxArrayString get_countries(const wxString& continent) {
		if (_continent_hash.find(continent)==_continent_hash.end() ) {
			return wxArrayString();
		}
		
		return _continent_hash[continent];
	}
	wxArrayString get_mirrors(const wxString& country) {
		if (_country_hash.find(country)==_country_hash.end() ) {
			return wxArrayString();
		}
		
		return _country_hash[country];
	}
	
	wxString get_url(const wxString& mirror) {
		if (_mirror_hash.find(mirror)==_mirror_hash.end() ) {
			return wxString();
		}
		
		return _mirror_hash[mirror];
	}
	
	const wxArrayString& get_mirrors() {
		return _mirrors;
	}
	
	virtual ~MirrorsList();
	
protected:
	MirrorsList();
	
	bool _reload_mirrors();
	
	ArrayStringHash _continent_hash;
	ArrayStringHash _country_hash;
	StringHash _mirror_hash;
	
	wxArrayString _mirrors;
	wxString _mirrorlst_path;
	
	static MirrorsList self;
};

#endif /* MIRRORSLST_H_ */
